package cn.gson.springmvc.model.pojos;

import javax.persistence.*;
import java.sql.Date;
import java.util.Collection;
import java.util.Objects;

@Entity
public class Supplier {
    private int supplierId;
    private String supplierName;
    private String linkman;
    private String phone;
    private String location;
    private Date creationTime;
    private Collection<Drug> drugsBySupplierId;
    private Collection<Purchase> purchasesBySupplierId;
    private Collection<ReturnGoods> returnGoodsBySupplierId;

    @Id
    @Column(name = "supplier_id", nullable = false)
    public int getSupplierId() {
        return supplierId;
    }

    public void setSupplierId(int supplierId) {
        this.supplierId = supplierId;
    }

    @Basic
    @Column(name = "supplier_name", nullable = true, length = 30)
    public String getSupplierName() {
        return supplierName;
    }

    public void setSupplierName(String supplierName) {
        this.supplierName = supplierName;
    }

    @Basic
    @Column(name = "linkman", nullable = true, length = 30)
    public String getLinkman() {
        return linkman;
    }

    public void setLinkman(String linkman) {
        this.linkman = linkman;
    }

    @Basic
    @Column(name = "phone", nullable = true, length = 30)
    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Basic
    @Column(name = "location", nullable = true, length = 30)
    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    @Basic
    @Column(name = "creation_time", nullable = true)
    public Date getCreationTime() {
        return creationTime;
    }

    public void setCreationTime(Date creationTime) {
        this.creationTime = creationTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Supplier supplier = (Supplier) o;
        return supplierId == supplier.supplierId &&
                Objects.equals(supplierName, supplier.supplierName) &&
                Objects.equals(linkman, supplier.linkman) &&
                Objects.equals(phone, supplier.phone) &&
                Objects.equals(location, supplier.location) &&
                Objects.equals(creationTime, supplier.creationTime);
    }

    @Override
    public int hashCode() {
        return Objects.hash(supplierId, supplierName, linkman, phone, location, creationTime);
    }

    @OneToMany(mappedBy = "supplierBySupplierId")
    public Collection<Drug> getDrugsBySupplierId() {
        return drugsBySupplierId;
    }

    public void setDrugsBySupplierId(Collection<Drug> drugsBySupplierId) {
        this.drugsBySupplierId = drugsBySupplierId;
    }

    @OneToMany(mappedBy = "supplierBySupplierId")
    public Collection<Purchase> getPurchasesBySupplierId() {
        return purchasesBySupplierId;
    }

    public void setPurchasesBySupplierId(Collection<Purchase> purchasesBySupplierId) {
        this.purchasesBySupplierId = purchasesBySupplierId;
    }

    @OneToMany(mappedBy = "supplierBySupplierId")
    public Collection<ReturnGoods> getReturnGoodsBySupplierId() {
        return returnGoodsBySupplierId;
    }

    public void setReturnGoodsBySupplierId(Collection<ReturnGoods> returnGoodsBySupplierId) {
        this.returnGoodsBySupplierId = returnGoodsBySupplierId;
    }
}
